<template>
	<div class="components-container">
        <div class="header-form">
            <div class="layui-inline">
                <label>处理日期从</label>
                <el-date-picker v-date v-model="selectData.ChddateGreaterAndEquals" type="date" placeholder="输入日期"/>
                 到 <el-date-picker v-date v-model="selectData.ChddateLessAndEquals" type="date" placeholder="输入日期"/>
            </div>
            <el-button type="primary" @click="btnSearch" :loading="this.$store.state.isloading">搜索</el-button>
            <el-button  @click="btnRepeat">重置</el-button>
        </div>
        <dataTable :headList="headList" :dataList="dataList" :pageOrder="pageOrder" @pageChange="pageChange" @selectRow="selectRow" :hiddenColumn="hiddenColumn" :hiddenPageOrder="false" :height="height"></dataTable>
        <h2 style="text-align:center;">{{message}}</h2>
        <!-- 详情 -->
        <sweet-modal ref="dialogInfo" class="dialog" :sweetModalWidth="sweetModalWidth" :sweetModalMaxWidth="sweetModalMaxWidth">
          <h3>{{ title }}</h3>
          <br/>
          <dataTable :headList="headListInfo" :dataList="dataListInfo" :pageOrder="pageOrderInfo"  @pageChange="pageChangeInfo" :hiddenColumn="hiddenColumn"></dataTable>
        </sweet-modal>
	</div>
</template>
<style rel="stylesheet/scss" lang="scss" scoped>
@import "src/styles/common.scss";
.el-button + .el-button {
  margin-left: 0;
}
.btn {
  text-align: center;
}
</style>
<script>
import dataTable from "@/components/Table/DataTable";
import apiBase from "@/api/apiBase.js";
import { formatDate, timeStringToDate } from "@/utils/date.js";
import { manage } from "@/mixins/managePage.js";
import sweetModal from "@/components/sweetModal";

const INFO = "详情";

export default {
  name: "saleStatistics",
  mixins: [manage],
  data() {
    return {
      selectData: {
        ChddateGreaterAndEquals:null,
        ChddateLessAndEquals:null
      },
      chdData: {},
      height:"620",
      ChdstatusEquals: {},
      chargetype: [],
      chaTypes: [],
      title: null,
      order: null,
      message: null,
      //价格历史
      dataListInfo: [],
      headListInfo: [],
      //分页和排序
      pageOrderInfo: {
        orderType: null,
        orderSort: null,
        totalNum: null,
        pageSize: 10,
        currentPage: 1
      },
      sweetModalWidth: 80,
      sweetModalMaxWidth: 1000,
      hiddenColumn: false
    };
  },
  methods: {
    //功能操作
    operate(order) {
      this.order = order;
      this.dataRepeat();
      switch (this.order) {
        case INFO:
          this.title = "火化业务报表详情";
          this.dataInfo();
          this.$refs.dialogInfo.open();
          break;
        default:
      }
    },
    getColumns() {
      let data = {};
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Column.GetChargesRecordColumns,
        res => {
          this.headList = res.data.content;
        }
      );
    },
    getData() {
      let Data = JSON.parse(JSON.stringify(this.selectData));
      Data.ChddateGreaterAndEquals= formatDate(Data.ChddateGreaterAndEquals,"yyyyMMdd");
      Data.ChddateLessAndEquals= formatDate(Data.ChddateLessAndEquals,"yyyyMMdd");
      let data = {
        PageIndex: 1,
        PageSize: 200,
        OrderBy: this.pageOrder.orderType,
        OrderByType: this.pageOrder.orderSort,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Report.QueryChargesRecord,
        res => {
          this.dataList = res.data.content.OutData;
          this.message = res.data.content.Message;
          this.pageOrder.totalNum = res.data.content.RecordCount;
        }
      );
    },
    //收费项目详情
    dataInfo() {
      this.dataListInfo = [];
      var Data = {
        ChaidEquals: this.currentRow.CHLCHAID
      };
      let data = {
        PageIndex: this.pageOrderInfo.currentPage,
        PageSize: this.pageOrderInfo.pageSize,
        OrderBy: this.pageOrderInfo.orderType,
        OrderByType: this.pageOrderInfo.orderSort,
        Data: Data
      };
      apiBase.DoService(
        data,
        apiBase.getApiAdress().Report.QuerySaleStatisticsDetail,
        res => {
          this.dataListInfo = res.data.content.OutData;
          this.pageOrderInfo.totalNum = res.data.content.RecordCount;
        }
      );
    },
    
    //查询条件重置
    btnRepeat() {
      this.selectData = {};
      this.selectData.ChddateGreaterAndEquals=new Date();
      this.selectData.ChddateGreaterAndEquals.setDate(1);
      this.getData();
    },
    //分页和排序
    pageChangeInfo(value) {
      this.pageOrderInfo = value;
      this.dataInfo();
    },
    //数据重置
    dataRepeat() {
      this.chdData = {};
    },
  },
  mounted() {},
  components: {
    dataTable,
    sweetModal
  },
    //当前选中行
  selectRow(row) {
    this.currentRow = row;
    this.$emit("selectRow", row, "");
  },
  created() {
    this.selectData.ChddateGreaterAndEquals=new Date();
    this.selectData.ChddateGreaterAndEquals.setDate(1);
    this.getColumns();
    this.getData();
    this.headListInfo=[{"ColumnAlign":"center","ColumnKey":"CHLMONEY","ColumnName":"单价","ColumnOrder":"CHLMONEY"},
      {"ColumnAlign":"center","ColumnKey":"CHLNUM","ColumnName":"数量","ColumnOrder":"CHLNUM"},
      {"ColumnAlign":"center","ColumnKey":"CHLMOUNT","ColumnName":"应收金额","ColumnOrder":"CHLMOUNT"},
      {"ColumnAlign":"center","ColumnKey":"CHLREDUCTION","ColumnName":"减免金额","ColumnOrder":"CHLREDUCTION"},
      {"ColumnAlign":"center","ColumnKey":"CHLDISCOUNT","ColumnName":"优惠金额","ColumnOrder":"CHLDISCOUNT"},
      {"ColumnAlign":"center","ColumnKey":"CHLRECEIVED","ColumnName":"实收金额","ColumnOrder":"CHLRECEIVED"},];
    
  }
};
</script>